package com.lepu.app.fun.hospital.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.core.lib.application.BaseFragmentActivity;
import com.eyzhs.app.R;
import com.lepu.app.fun.hospital.HospitalConsultDetailActivity;
import com.lepu.app.fun.my.bean.BeanQuestionAnswer;

public class AdapterHospitalQuestionList extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	private Context mContext = null;
	private ArrayList<BeanQuestionAnswer> mArrayList = null;

	public AdapterHospitalQuestionList(Context context,
			ArrayList<BeanQuestionAnswer> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.my_question_hospital_list_item, null);

			holder = new ViewHolder();

			TextView titleTextView = (TextView) convertView
					.findViewById(R.id.titleTextView);

			holder.titleTextView = titleTextView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final BeanQuestionAnswer item = mArrayList.get(position);
		
		holder.titleTextView.setText(String.valueOf(position+1)+"."+item.ARQuestion);
		
		holder.titleTextView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(mContext,HospitalConsultDetailActivity.class);
				intent.putExtra("question", item.ARQuestion);
				intent.putExtra("answer", item.ARAnswer);
				((BaseFragmentActivity)mContext).startActivity(intent, true);
			}
		});

		return convertView;
	}

	private static class ViewHolder {

		TextView titleTextView;

	}
}
